package com.example.huadi1.service.Imp;

import com.example.huadi1.dto.Account;
import com.example.huadi1.mapper.LoginMapper;
import com.example.huadi1.service.LoginService;
import com.example.huadi1.utils.AjaxResult;
import com.example.huadi1.utils.JWTUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    private LoginMapper loginMapper;
    @Override
    public AjaxResult login(Account account){
        Account account1 = loginMapper.login(account);;

        if (account1 == null) {
            return AjaxResult.error("用户不存在");
        }
        if (!account1.getPassword().equals(account.getPassword())) {
            return AjaxResult.error("用户名或密码错误");
        }
        String token = JWTUtil.generateToken(account.getAccount());
        account1.setToken(token);
        return AjaxResult.success(account1);
    }


}
